package com.zstu.mall.service.impl;

import com.zstu.mall.dao.ProductActivityDao;
import com.zstu.mall.dao.ProductDao;
import com.zstu.mall.entity.Product;
import com.zstu.mall.service.ProductService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.zstu.mall.common.BaseServiceImpl;
import com.zstu.mall.service.UserOrderService;
import com.zstu.mall.entity.UserOrder;
import com.zstu.mall.dao.UserOrderDao;

import java.util.List;

/**
 * @author     : wuyc
 * @description: UserOrderServiceImpl
 * @date       : Created in 2019/11/24
 */
@Service
public class UserOrderServiceImpl extends BaseServiceImpl<UserOrder, String, UserOrderDao> implements UserOrderService {

	@Autowired
	private UserOrderDao userOrderDao;

	@Autowired
	private ProductService productService;

	/**
	 * 根据订单Id查询
	 * @param orderId
	 * @return
	 */
	@Override
	public List<UserOrder> findByOrderId(String orderId){
		List<UserOrder> userOrders = userOrderDao.findByOrderId(orderId);//购物车状态通过id = shop_cart_ + user_id 来识别
		for(UserOrder userOrder : userOrders){
			//添加商品信息
			if(productService.exists(userOrder.getProductId()) == true){
				Product product = productService.get(userOrder.getProductId());
				System.out.println(product.toString());
				userOrder.setProduct(product);
			}
			//移除非订单状态
			if(!userOrder.getStatus().equals("0"))
				userOrders.remove(userOrder);
		}
		return userOrders;
	}

}
